package rickyGame.game.action.ai
{
	import flash.geom.Point;
	
	import ricky.game.Actor;
	import ricky.game.Actor2D;
	import ricky.game.action.Act2D;
	import ricky.quadtree.Leaf;
	import ricky.quadtree.Quadtree;
	import ricky.utils.FrameManager;
	import ricky.utils.TimeServer;
	import ricky.utils.Utils;
	
	import rickyGame.controller.Controller;
	import rickyGame.controller.state.State;
	import rickyGame.game.GameState;
	import rickyGame.game.Player;
	import rickyGame.game.action.MoveLeafAction;
	import rickyGame.game.scene.Pathfinder;
	
	/**
	 * 什么都不做
	 */
	public class IdleAi extends Act2D
	{
		public function IdleAi(actor:Actor2D,contime:Number=0)
		{
			super(actor);
//			this._par=par;
			this._state=AiType.IdleAi;
			this._animProperty="stand";
			_type="IdleAi";
			
			_contime=contime;
			
			
		}
		
		override public function begin():void
		{
			if(_contime>0)
				this._endTime=new Date().getTime();
			
			FrameManager.inst.addLogic(getActor());
			_last=TimeServer.now();
			super.begin();
		}
		
		override public function action(timeline:Number):void
		{
			var dt:Number=timeline-_last;
			if(dt>= 1200)//
			{
				_last=timeline;
			}
			
			if(_endTime!=0 && timeline>_endTime)
				this.complete();

		}
		
		override public function end():void
		{
			FrameManager.inst.removeLogic(getActor());
//			JDebug.trace("IdleAi 结束控制 end");

		}
		
		public function checkTransition():void
		{
			var rang:int=actor.data.rangeVisible;
			var me:Player=Controller.instance.actor;
			var dis:int=Utils.gridDistance1(me.gridX,me.gridY,Actor2D(actor).gridX,Actor2D(actor).gridY);
			
			var m:int=Math.random()*100;

//			JDebug.trace("IdleAi --checkTransition");
//			if(dis<rang)
//			{
////				if(me.fightPro.hp.agileValue>=me.fightPro.hp.value*0.8 && me.property.level>10 || m<=5)
////				{
//				if(m<=50)
//				{
////					this.end();
////					var evade:EvadeAi=new EvadeAi(this.actor);
////					this.actor.addAct(evade);
//					var seek:SeekAi=new SeekAi(actor,me);
//					actor.addAct(seek);
//					return;
//				}
//			}else
			{
				if(m<15) //30几率 游荡
				{
					
//					this._animProperty="run";
//					this.end();
					var wander:WanderAi=new WanderAi(Actor2D(actor));
					Actor2D(actor).addAct(wander);
				}else
				{
					
					var c:int=1;
					if(this.actor.group==1)
						c=0;
					var point:Array=GameState.inst.scene.mapData.getBorn(c);
					var p:Point=new Point(point[0]*40,point[1]*30);
					var path:Array=State.pathFinder(p,actor);
					var mv:MoveLeafAction=new MoveLeafAction(Actor2D(actor),null,path);
					Actor2D(actor).addAct(mv);
					
//					if(this.actor.group==0)
						
					
//					if(m<60)
//					{
////						this.animProperty="death";
////						super.begin();
//					}
//					else 
//					{
////						this.animProperty="attack";
////						super.begin();
//					}
				}
			}

		}
		//
		private var _contime:Number=0;
		private var _endTime:Number=0;
		private var _last:Number;
	}
}